package com.bigdata.warehouse.util;

import java.sql.*;
public class TestClickhouse {
    private static Connection connection = null;
    static {
        try {
            Class.forName("ru.yandex.clickhouse.ClickHouseDriver");// 驱动包
            String url = "jdbc:clickhouse://slave3:8123/system";// url路径
            String user = "default";// 账号
            String password = "123456";// 密码
            connection = DriverManager.getConnection(url, user, password);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static void main(String[] args) throws SQLException {
        Statement statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery("select * from system.functions");
        ResultSetMetaData metaData = resultSet.getMetaData();
        int columnCount = metaData.getColumnCount();
        while (resultSet.next()) {
            for (int i = 1; i <= columnCount; i++) {
                System.out.println(metaData.getColumnName(i) + ":" + resultSet.getString(i));
            }
        }
    }
}

